package com.splant.android.smart.UILevel.Community;

import android.content.Context;
import android.content.Intent;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.splant.android.R;
import com.splant.android.smart.ModelLevel.TimerWater;
import com.splant.android.smart.UILevel.Community.fragments.Garden_AreaList_Adapter;

import java.io.Serializable;
import java.util.List;

/**
 * Created by Administrator on 2017/8/9.
 */

public class Garden_TimeWater_Adapter extends BaseAdapter {

    private Context mContext;
    private LayoutInflater inflater;
    private List<TimerWater> timerWaterList;

    public Garden_TimeWater_Adapter(Context context, List<TimerWater> timerWaterList) {

        mContext = context;
        inflater = LayoutInflater.from(context);
        this.timerWaterList = timerWaterList;
    }
    public void setTimerWaterList(List<TimerWater> timerWaterList)
    {
        this.timerWaterList=timerWaterList;
    }

    @Override
    public int getCount() {
        return timerWaterList.size();
    }

    @Override
    public Object getItem(int position) {
        return timerWaterList.get(position);
    }

    @Override
    public long getItemId(int position) {
        return 0;
    }

    @Override
    public View getView(final int position, View convertView, ViewGroup parent) {

        ViewHolder viewHolder;
        if (convertView == null) {

            convertView = inflater.inflate(R.layout.garden_timerwater_adapter_item, null);// 生成条目对象
            viewHolder = new ViewHolder();
            viewHolder.tv_startTime = (TextView) convertView.findViewById(R.id.tv_startTime);
            viewHolder.tv_waterLength = (TextView) convertView.findViewById(R.id.tv_waterLength);
            viewHolder.img_edit= (ImageView) convertView.findViewById(R.id.img_edit);
            convertView.setTag(viewHolder);

        } else
            viewHolder = (ViewHolder) convertView.getTag();

        TimerWater timerWater = timerWaterList.get(position);
        viewHolder.tv_startTime.setText(timerWater.getStartTime());
        viewHolder.tv_waterLength.setText(String.valueOf(timerWater.getWaterLength())+"分钟");
        viewHolder.img_edit.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {

                Intent intent=new Intent(mContext,Garden_TimerWaterEdit_Activity.class);
                intent.putExtra("timerWater",timerWaterList.get(position));

                mContext.startActivity(intent);

            }
        });

        return convertView;
    }

    public class ViewHolder {
        public TextView tv_startTime;
        public TextView tv_waterLength;
        public ImageView img_edit;
    }
}
